package main

import "fmt"

func main() {
	var book1 Books
	book1.title = "三国演义"
	book1.author = "小罗"
	book1.book_id = 1

	book2 := Books{
		title:  "西游记",
		author: "吴承恩",
	}

	fmt.Printf("Book 1 title : %s\n", book1.title)
	fmt.Printf("Book 1 author : %s\n", book1.author)
	fmt.Printf("Book 2 subject : %s\n", book2.subject)
	fmt.Printf("Book 2 book_id : %d\n", book2.book_id)

	//结构体指针
	var bookip *Books = &book2
	bookip.name = "lalal"
	bookip.person = Persion{
		name: "团长",
		address: Address{
			city:  "杭州",
			state: "1",
		},
	}
	fmt.Printf("bookip book_id : %d\n", bookip.book_id)
	fmt.Printf("bookip book_name : %s\n", bookip.name)
	fmt.Printf("bookip book_name : %s\n", bookip.person.name)

}

type Books struct {
	title   string
	author  string
	subject string
	book_id int
	//在类型中，使用不写字段名的方式，使用另一个类型
	Persion
	person Persion
}

type Persion struct {
	name string
	age  int
	/*结构体嵌套*/
	address Address
}

type Address struct {
	city, state string
}
